package EventManager;

import java.util.ArrayList;

import Driver.Facade;
import Model.Event;

/**
 * A User request that returns the list of all events in the catalogue, if sustained.
 * @author Yury Kitaev
 *
 */
public class ViewAllEventsRequest extends UserRequest
{
	private ArrayList<Model.Event> events;
	private boolean onlyOpen;
	
	public ViewAllEventsRequest(boolean onlyOpen)
	{
		super();
		this.onlyOpen = onlyOpen;
	}

	/**
	 * Processes the request and updates itself. Sets the "events" attribute to the list of all events in the catalog.
	 */
	@Override
	public void process()
	{
		ArrayList<Event> eventsRetrieved = Facade.getCatalog().getEvents(onlyOpen);
		if (null != eventsRetrieved
				&& eventsRetrieved.size() > 0)
		{
			setEvents(eventsRetrieved);
			setStatus(RequestStatus.Sustained);
		}
		else
		{
			setEvents(null);
			setStatus(RequestStatus.Refused);
		}
	}
	
	public ArrayList<Model.Event> getEvents() 
	{
		return events;
	}

	public void setEvents(ArrayList<Model.Event> events) 
	{
		this.events = events;
	}

	@Override
	public String toString() 
	{
		return "View All Events" + (onlyOpen? " that are open" : ", both closed and open");
	}
}
